package com.csq.cms.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.csq.cms.mapper.ParttimeInfoMapper;
import com.csq.cms.pojo.FavoriteEnterpriseInfo;
import com.csq.cms.pojo.FavoriteParttimeInfo;
import com.csq.cms.service.FavoriteService;
import com.csq.common.pojo.ReturnResult;
import com.csq.common.pojo.StatusCode;
import com.csq.manager.mapper.FavoriteMapper;
import com.csq.manager.pojo.Favorite;
import com.csq.manager.pojo.Parttime;
import com.csq.manager.pojo.ParttimeExample;
import com.csq.manager.pojo.ParttimeExample.Criteria;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
@Service
public class FavoriteServiceImpl implements FavoriteService {

	@Autowired
	private FavoriteMapper favoriteMapper;
	
	@Autowired
	private ParttimeInfoMapper parttimeInfoMapper;
	
	@Override
	public ReturnResult addFavorite(Favorite favorite) {
		// TODO Auto-generated method stub
		
		
		
		int insertSelective = favoriteMapper.insertSelective(favorite);
		if (insertSelective == 0) {
			return ReturnResult.build(StatusCode.INSERTFAILL, "插入失败");
		}

		return ReturnResult.ok();
	}

	@Override
	public ReturnResult deleteFavorite(Integer favoriteId) {
		
		
		int deleteSelective = favoriteMapper.deleteByPrimaryKey(favoriteId);
		if (deleteSelective == 0) {
			return ReturnResult.build(StatusCode.DELETEFAIL, "刪除失败");
		}

		return ReturnResult.ok();
	}

	@Override
	public PageInfo<FavoriteParttimeInfo> getFavoriteParttime(
			Integer accountId, Integer page, Integer row) {
		// TODO Auto-generated method stub
		if (page == null) {
			page = 1;
		}
		if (row == null) {
			row = 10;
		}

		// 分页设置
		PageHelper.startPage(page, row);
		// 执行查询

		List<FavoriteParttimeInfo> list = parttimeInfoMapper.getFavoriteParttime(accountId);
		// 取分页信息
		PageInfo<FavoriteParttimeInfo> pageInfo = new PageInfo<>(list);
		System.out.println("总记录数：" + pageInfo.getTotal());
		System.out.println("总页数：" + pageInfo.getPages());
		System.out.println(list.size());
		return pageInfo;
	}

	@Override
	public PageInfo<FavoriteEnterpriseInfo> getFavoriteEnterprise(
			Integer enterpriseId, Integer page, Integer row) {
		// TODO Auto-generated method stub
		if (page == null) {
			page = 1;
		}
		if (row == null) {
			row = 10;
		}

		// 分页设置
		PageHelper.startPage(page, row);
		// 执行查询

		List<FavoriteEnterpriseInfo> list = parttimeInfoMapper.getFavoriteEnterprise(enterpriseId);
		// 取分页信息
		PageInfo<FavoriteEnterpriseInfo> pageInfo = new PageInfo<>(list);
		System.out.println("总记录数：" + pageInfo.getTotal());
		System.out.println("总页数：" + pageInfo.getPages());
		System.out.println(list.size());

		return pageInfo;
	}

}
